﻿using System;
using System.Runtime.InteropServices;
using UnityEngine;

public unsafe class vmrp:MonoBehaviour
{
    private void Start()
    {
        int[] da = new int[10] {1,2,3,4,5,6,7,8,9,10 };
        IntPtr p = Marshal.UnsafeAddrOfPinnedArrayElement(da, 0);
        byte* p1 = (byte*)p;
        long ps = (long)p1;
        byte* p2 = (byte*)ps;
        int a = ~3;
        long ps2 = ps & a;
        long ps3 = ps & ~3;
        long ps4 = ps + 4;
        byte* p3 = (byte*)ps2;
        byte* p4 = (byte*)ps3;
        byte* p5 = (byte*)ps4;
        uint ss=(uint )p1;
        ss += 8;
        long ss2=(long)ss;
        byte* p6 = (byte*)ss2;
        //byte* p3 = (byte*)ps;
        //int vv = *((int*)p3);
        //IntPtr p2 = new IntPtr(p1);
        //int v = (int)(p2.ToInt32());
        GlobalMembers.Main(0,null);

        //int f = 2;
        //IntPtr a = new IntPtr(f);

        //int f2 = (int)a;
        //int f3 = *((int*)a.ToPointer ());

        //byte[] outputData = new byte[2] { 1,2};
        //void* p;
        //IntPtr ptr;
        //fixed (byte* pc = outputData)
        //{
        //    p = (void*)(pc+1);
        //    ptr = (IntPtr)p;// new IntPtr(p);
        //    byte v = *(pc+1);
        //    int v2 = ptr.ToInt32();
        //}

    }

    private void OnApplicationQuit()
    {
        foreach(FILE file in GlobalMembers.handles)
        {
            if (file != null)
                file.Close();
        }
    }
}